<%@page import="com.wanmait.movies.vo.Maneger"%>
<%@page import="com.wanmait.movies.vo.MovieCountry"%>
<%@page import="com.wanmait.movies.vo.MovieType"%>
<%@page import="com.wanmait.movies.vo.MovieLanguage"%>
<%@page import="com.wanmait.movies.vo.Actor"%>
<%@page import="com.wanmait.movies.vo.Director"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%String path =request.getContextPath();%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-3.5.1.min.js"></script>
    <% Maneger m =(Maneger)session.getAttribute("maneger");
	if(m==null){
	response.sendRedirect(request.getContextPath()+"/manegerlog.jsp");
	}%>



<!-- 导演 -->
<script type="text/javascript">
	$(function(){
		$("#directorfind").focus(function(){
			$("#directorlist").css("display","block");
		});
		
	});
	
	$(function(){
		$("#directorlist").on("click",".alldirector",function(){
			var directorid=$("#directorid").val();
			var director = $("#director").html();
			
			var ids =$(this).attr("did");
			var dis =$(this).find("span").html();
			
			var directorids =directorid.split(",");
			
				for(var i=0;i<directorids.length;i++){
					if(directorids[i]==ids){
						
						alert("选择重复");
						return;
					}
				}
			if(confirm("确定添加？")){
				$("#directorid").val(directorid+ids+",")
				$("#director").html(director+dis+",")
				
				$("#directorlist").css("display","none");
			}
			
		});
	});
	
	$(function(){
		$("#directorinput").click(function(){
			
			var name =$("#directorfind").val();
			
			$.ajax({
				url:"/movies/ManegerServlet?action=findDirector",
				async:false,
				type:"get",
				data:"name="+name,
				success:function(s){
					
					$("#directorfind").val("");
				if(s=="0"){
					alert("查无此人，请先添加");
				}else{
					var directors =JSON.parse(s);	
					$("#directorlist").html("");
					var closed=$(" <div><a href='javascript:void(0);'>x</a></div>");
					closed.addClass("closedirectorlist");
					$("#directorlist").append(closed);
					
					for(var i=0;i<directors.length;i++){
						
						var divs =$("<div></div>");
						divs.addClass("alldirector");
						divs.attr("did",directors[i].id);
						
						var imgs = $("<img >");
						imgs.attr("src","<%=path%>/images/"+directors[i].directorImage);
						divs.append(imgs);
						
						var br =$("<br>");
						divs.append(br);
						
						var sp =$("<span></span>");
						sp.html(directors[i].directorName);
						divs.append(sp);
						
						$("#directorlist").append(divs);
					}
				}
									
				}
			});
		});
	});
	$(function(){
		$("#directordelete").click(function(){
			var directorid=$("#directorid").val();
			var director = $("#director").html();
			
			var ids = directorid.split(",");
			var dis = director.split(",");
			var id="";
			var di="";
			for(var i=0;i<ids.length-2;i++){
				id= id+ids[i]+",";
				di= di+dis[i]+",";
			}
			
			$("#directorid").val(id);
		    $("#director").html(di);
		});
	});
	
	$(function(){
		$("#directoradd").click(function(){
				$("#addDirector").css("display","block");
		})
	});
	$(function(){
		$("#addDirector").on("click",".closeadddirector",function(){
			var s=$("#addDirector").css("display","none");
		})
	});
	
	
	$(function(){
		$("#directordiv").on("click",".closedirectorlist",function(){
			var s=$("#directorlist").css("display","none");
		})
	});
	
</script>

<!-- 演员 -->
<script type="text/javascript">
$(function(){
	$("#actorfind").focus(function(){
		$("#actorlist").css("display","block");
	});
	
});

$(function(){
	$("#actorlist").on("click",".allactor",function(){
		var actorid=$("#actorid").val();
		var actor = $("#actor").html();
		
		var ids =$(this).attr("aid");
		var dis =$(this).find("span").html();
		
		var actorids =actorid.split(",");
		
			for(var i=0;i<actorids.length;i++){
				if(actorids[i]==ids){
					
					alert("选择重复");
					return;
				}
			}
		if(confirm("确定添加？")){
			$("#actorid").val(actorid+ids+",")
			$("#actor").html(actor+dis+",")
			
			$("#actorlist").css("display","none");
		}
		
	});
});

$(function(){
	$("#actorinput").click(function(){
		
		var name =$("#actorfind").val();
		
		$.ajax({
			url:"/movies/ManegerServlet?action=findActor",
			async:false,
			type:"get",
			data:"name="+name,
			success:function(s){
				
				$("#actorfind").val("");
			if(s=="0"){
				alert("查无此人，请先添加");
			}else{
				var actors =JSON.parse(s);	
				$("#actorlist").html("");
				var closed=$(" <div><a href='javascript:void(0);'>x</a></div>");
				closed.addClass("closeactorlist");
				$("#actorlist").append(closed);
				
				for(var i=0;i<actors.length;i++){
					
					var divs =$("<div></div>");
					divs.addClass("allactor");
					divs.attr("aid",actors[i].id);
					
					var imgs = $("<img >");
					imgs.attr("src","<%=path%>/images/"+actors[i].actorImage);
					divs.append(imgs);
					
					var br =$("<br>");
					divs.append(br);
					
					var sp =$("<span></span>");
					sp.html(actors[i].actorName);
					divs.append(sp);
					
					$("#actorlist").append(divs);
				}
			}
								
			}
		});
	});
});
$(function(){
	$("#actordelete").click(function(){
		var actorid=$("#actorid").val();
		var actor = $("#actor").html();
		
		var ids = actorid.split(",");
		var dis = actor.split(",");
		var id="";
		var di="";
		for(var i=0;i<ids.length-2;i++){
			id= id+ids[i]+",";
			di= di+dis[i]+",";
		}
		
		$("#actorid").val(id);
	    $("#actor").html(di);
	});
});

$(function(){
	$("#actoradd").click(function(){
			$("#addActor").css("display","block");
	})
});

$(function(){
	$("#addActor").on("click",".closeaddactor",function(){
		$("#addActor").css("display","none");
	})
});


$(function(){
	$("#actordiv").on("click",".closeactorlist",function(){
		$("#actorlist").css("display","none");
	})
});


$(function(){
	$("#languageadd").click(function(){
			$("#addLanguage").css("display","block");
	})
});
//关闭添加语言
$(function(){
	$("#addLanguage").on("click",".closeaddlanguage",function(){
		$("#addLanguage").css("display","none");
		
		$.ajax({
			url:"/movies/ManegerServlet?action=languageList",
			async:false,
			type:"get",
			data:"name="+name,
			success:function(s){
				var list =JSON.parse(s);
				$("#languagelist").children().remove();
				for(var i =0;i<list.length;i++){
					var op =$("<option></option>");
					op.html(list[i].languageType);
					op.val(list[i].id);
					$("#languagelist").append(op);
				}			
			}
		});
		
	})
});


$(function(){
	$("#countryadd").click(function(){
			$("#addcountry").css("display","block");
	})
});
//关闭添加地区
$(function(){
	$("#addcountry").on("click",".closeaddcountry",function(){
		$("#addcountry").css("display","none");
		$.ajax({
			url:"/movies/ManegerServlet?action=countryList",
			async:false,
			type:"get",
			data:"name="+name,
			success:function(s){
				var list =JSON.parse(s);
				$("#countrylist").children().remove();
				for(var i =0;i<list.length;i++){
					var op =$("<option></option>");
					op.html(list[i].country);
					op.val(list[i].id);
					$("#countrylist").append(op);
				}	
			
								
			}
		});
		
	})
});

$(function(){
	$("#typeadd").click(function(){
		$("#addtype").css("display","block");
	})
});
//关闭添加类型
$(function(){
	$("#addtype").on("click",".closeaddtype",function(){
		$("#addtype").css("display","none");
		
		$.ajax({
			url:"/movies/ManegerServlet?action=typeList",
			async:false,
			type:"get",
			data:"name="+name,
			success:function(s){
				var list =JSON.parse(s);
				$("#typelist").children().remove();
				for(var i =0;i<list.length;i++){
					var op =$("<option></option>");
					op.html(list[i].movieType);
					op.val(list[i].id);
					$("#typelist").append(op);
				}	
			
								
			}
		});
		
	})
});
</script>


<style type="text/css">
	#directorlist img {
	width:100px;
	height:100px;
	border-radius: 50px;
	border:1px solid gray;
	}

	#directorlist{
	display:none;
	width:700px;
	overflow:auto;
	height:320px;
	border-radius:10px;
	border:1px solid #ddd;
	}
	.closedirectorlist{
	margin-left:620px;
	}
	.alldirector{
	width:120 px;
	float:left;
	margin-left:50px;
	margin-top:10px;
	text-align: center;
	font-size:15px;
	}
	#addDirector{
	display:none;
	width:400px;
	height:100%;
	border:1px solid #ddd;
	border-radius: 10px;
	}
	.closeadddirector{
	margin-left:350px;
	}
	
	#directorfind{
	margin-left:210px;
	}
	#actorlist img {
	width:100px;
	height:100px;
	border-radius: 50px;
	border:1px solid gray;
	}

	#actorlist{
	display:none;
	width:700px;
	overflow:auto;
	height:320px;
    border-radius:10px;
	border:1px solid #ddd;
	}
	.closeactorlist{
	margin-left:620px;
	}
	.allactor{
	width:120 px;
	float:left;
	margin-left:50px;
	margin-top:10px;
	text-align: center;
	
	}
	#addActor{
	display:none;
	width:400px;

	height:100%;
	border:1px solid #ddd;
	border-radius: 10px;
	}
	.closeaddactor{
	margin-left:350px;
	}
	#actorfind{
	margin-left:210px;
	}
	
	#addLanguage{
	display:none;
	width:400px;

	height:100%;
	border:1px solid #ddd;
	border-radius: 10px;
	}
	.closeaddlanguage{
	margin-left:350px;
	}
	#addtype{
	display:none;
	width:400px;

	height:100%;
	border:1px solid #ddd;
	border-radius: 10px;
	}
	.closeaddtype{
	margin-left:350px;
	}
	#addcountry{
	display:none;
	width:400px;

	height:100%;
	border:1px solid #ddd;
	border-radius: 10px;
	}
	.closeaddcountry{
	margin-left:350px;
	}
	#addmovie{
	width:500px;
	margin:auto;
	}
	
	
	iframe{
	width:400px;
	height:100%;
	border:0px;
	}
	
	body{
	background-color:white;
	font-size:18px;
	font-weight: bold;
	}
	
	a{
	color:red;
	text-decoration: none;
	}
	
	input{
	
	margin:10px;
	}
	
	#submitmovie{ 
	width:500px;
	text-align: center;
	}
	.alldirector,.allactor span{
	font-size: 12px;
	}
	
	#director,#actor{
		font-size: 15px;
		color:blue;
	}
</style>

<script type="text/javascript">

$(function(){
	$("select").change();
});
//设置样式
$(function(){
	$("input[type=text]").css("width","150px");
	$("input[type=text]").css("height","20px");
	$("input[type=text]").css("border","2px solid gray");
	$("input[type=text]").css("border-radius","10px");
	
	$("input[type=button]").css("background-color","white");
	$("input[type=submit]").css("background-color","lightblue");
	
	$("input[type=submit]").css("width","200px");
	$("input[type=button],input[type=submit]").css("height","20px");
	$("input[type=button],input[type=submit]").css("font-size","15px");
	$("input[type=button],input[type=submit]").css("line-height","15px");
	$("input[type=button],input[type=submit]").css("font-weight","bold");
	$("input[type=button],input[type=submit]").css("border","2px solid gray");
	$("input[type=button],input[type=submit]").css("border-radius","10px");
	
	$("select").css("background-color","white");
	$("select").css("height","20px");
	$("select").css("width","100px");
	$("select").css("border","2px solid gray");
	$("select").css("border-radius","10px");
	$("select").css("font-size","15px");
	$("select").css("line-height","15px");
	$("select").css("font-weight","bold");
	
	$("input[type=date]").css("background-color","white");
	$("input[type=date]").css("height","20px");
	$("input[type=date]").css("width","150px");
	$("input[type=date]").css("border","2px solid gray");
	$("input[type=date]").css("border-radius","10px");
	$("input[type=date]").css("font-size","15px");
	$("input[type=date]").css("line-height","15px");
	$("input[type=date]").css("font-weight","bold");
	
	$("input[type=file]").css("background-color","white");
	$("input[type=file]").css("height","22px");
	$("input[type=file]").css("width","200px");
	$("input[type=file]").css("font-size","15px");
	$("input[type=file]").css("line-height","15px");
	$("input[type=file]").css("font-weight","bold");
	
});
</script>
</head>
<body>
	<form action="<%=path %>/ManegerServlet?action=submitMovie  " method="post" enctype="multipart/form-data" id="form">
	<div id="addmovie">
	&emsp;电影名 :<input type="text" name="movieName" id="movieName"><br><br>
	时&emsp;&emsp;长:  <input type="text" name="movieTime" id="movieTime"><br><br>
	语&emsp;&emsp;言:&emsp;<select id="languagelist" name="movieLanguage">
	        
		<%ArrayList<MovieLanguage> languageList =(ArrayList<MovieLanguage>)request.getAttribute("languageList");
			for(MovieLanguage language:languageList){%>
			<option value="<%=language.getId()%>"><%=language.getLanguageType() %></option>		
		<%	}
		%>
		
	  
	    </select><input type="button" id="languageadd" value="添加新语言"><br><br>
		 <br>
		  	<!-- 添加语言 -->
	    <div  id="addLanguage">
	       <div class =closeaddlanguage><a href="javascript:void(0);">x</a></div>
	        <iframe src="<%=path %>/addLanguage.jsp"></iframe>
	    </div>
		上映时间:&nbsp;<input type="date" name="showTime" id="showTime"><br><br>
	
	            类&emsp;&emsp;型:&emsp;<select id="typelist" name="movieType"> 
		
		<%ArrayList<MovieType> typeList =(ArrayList<MovieType>)request.getAttribute("typeList");
			for(MovieType type: typeList){%>
			<option value="<%=type.getId()%>"><%=type.getMovieType() %></option>		
		<%	}
		%>
		
	    </select><input type="button" id="typeadd" value="添加新类型"><br><br>
		 <br>
		  	<!-- 添加类型 -->
	    <div  id="addtype">
	       <div class =closeaddtype><a href="javascript:void(0);">x</a></div>
	        <iframe src="<%=path %>/addType.jsp"></iframe>
	    </div>
		
	            是否热映:&emsp;<select name="movieShow">
			<option value="1">是</option >
			<option value="0">否</option >
	      </select> 
		  <br><br>
			
	           地&emsp;&emsp;区:&emsp;<select id="countrylist" name="movieCountry">
	  		<%ArrayList<MovieCountry> countryList =(ArrayList<MovieCountry>)request.getAttribute("countryList");
			for(MovieCountry country: countryList){%>
			<option value="<%=country.getId()%>"><%=country.getCountry() %></option>		
		<%	}
		%>
	  
	      </select><input type="button" id="countryadd" value="添加新地区"><br><br>
		  <br>
		  	<!-- 添加地区 -->
	    <div  id="addcountry">
	       <div class =closeaddcountry><a href="javascript:void(0);">x</a></div>
	        <iframe src="<%=path %>/addCountry.jsp"></iframe>
	    </div>
	            简&emsp;&emsp;介: <br><br><textarea id = "introduce" name="movieIntroduce">
	  	
	  </textarea><br><br> 
	    <script type="text/javascript" src="<%=path %>/ueditor/ueditor.config.js"></script>
	  	<script type="text/javascript" src="<%=path %>/ueditor/ueditor.all.min.js"></script>
	  	<script type="text/javascript" >
	         //在线编辑器
		     var editor;
	         $(function(){
	        	 var item ={initialFrameWidth:300,
	        			 initialFrameHeight:200,
	        			 toolbars:[['bold','fontfamily','fontsize','simpleupload','insertimage','emotion','forecolor','scrawl']],
	        			 };
	        	 editor =UE.getEditor("introduce",item);
	         });
	  	
	  		function checkIntroduce(){
	  			var flag =editor.getContent();
	  			if(flag!=""){
	  				return true;
	  			}else{
	  				return false;
	  			}
	  		}
	  	</script>
	 &emsp;缩略图 :<input type="file" name="movieImage" id="movieImage"><br><br>   
	  海&emsp;&emsp; 报:<input type="file" name="moviePoster" id="moviePoster"><br><br>
	
	                  <input type="hidden" id="directorid" name="movieDirector">
	   导&emsp;&emsp;演: <span id="director"></span>
	   
	   <input type="button" id="directordelete" value="删除上步所选"><input type="button" id="directoradd" value="添加新导演">
	   <!-- 添加导演 -->
	    <div  id="addDirector">
	       <div class =closeadddirector><a href="javascript:void(0);">x</a></div>
	       <iframe src="<%=path %>/addDirector.jsp"></iframe>
	       
	    </div>
	   
	   <br><br>
	    	<div id="directordiv">
	    		 <div><input type="text"  id ="directorfind"><input type="button" id="directorinput" value="搜索"></div>
	    		 <div id="directorlist">
	    		 		<div class="closedirectorlist"><a href="javascript:void(0);">x</a></div>
	    		 		<%ArrayList<Director> directorList  =(ArrayList<Director>)request.getAttribute("directorList"); %>
	    		 		<%for(Director director:directorList){ %>
	    		 			<div class="alldirector" did="<%=director.getId()%>">
	    		 			    <img src ="<%=request.getContextPath()%>/images/<%=director.getDirectorImage()%>"><br>
	    		 				<br><span><%=director.getDirectorName()%></span>
	    		 			</div>
	    		 		<%} %>
	    		 	
	    		 </div>
	    	</div>
	        <br><br>
	        
	                  <input type="hidden" id="actorid" name="movieActor">
	    演&emsp;&emsp;员: <span id="actor"></span>
	 
	  <input type="button" id="actordelete" value="删除上步所选"><input type="button" id="actoradd" value="添加新演员">
	  	
	  		<!-- 添加演员 -->
	    <div  id="addActor">
	       <div class =closeaddactor><a href="javascript:void(0);">x</a></div>
	        <iframe src="<%=path %>/addActor.jsp"></iframe>
	    </div>
	  		
	  		<div id="actordiv">
	  			 <div><input type="text" id ="actorfind"><input type="button" id="actorinput" value="搜索"></div>
	  			 <div id="actorlist">
	  			 	
	  			 	<div class="closeactorlist"><a href="javascript:void(0);">x</a></div>
	    		 		<%ArrayList<Actor> actorList  =(ArrayList<Actor>)request.getAttribute("actorList"); %>
	    		 		<%for(Actor actor:actorList){ %>
	    		 			<div class="allactor" aid="<%=actor.getId()%>">
	    		 			    <img src ="<%=request.getContextPath()%>/images/<%=actor.getActorImage()%>">
	    		 				<br><span><%=actor.getActorName()%></span>
	    		 			</div>
	    		 		<%} %>
	    
	  			 </div>
	  		</div>
	  		<br><br>
	  		<div id="submitmovie"><input type="submit"  value="添&emsp;&emsp;&emsp;加"></div>
	  		<!-- 判断是否为空 -->
	  		<script type="text/javascript">
	  		function checkName(){
	  			var flag=$("#movieName").val();
	  			if(flag!=""){
	  				return true;
	  			}else{
	  				return false;
	  			}
	  		};
	  		
	  		function checkTime(){
	  			var flag=$("#movieTime").val();
	  			if(flag!=""){
	  				return true;
	  			}else{
	  				return false;
	  			}
	  		};
	  		
	  		function checkImage(){
	  			var flag=$("#movieImage").val();
	  			if(flag!=""){
	  				return true;
	  			}else{
	  				return false;
	  			}
	  		};
	  		
	  		function checkPoster(){
	  			var flag=$("#moviePoster").val();
	  			if(flag!=""){
	  				return true;
	  			}else{
	  				return false;
	  			}
	  		};
	  		
	  		function checkActor(){
	  			var flag=$("#actorid").val();
	  			if(flag!=""){
	  				return true;
	  			}else{
	  				return false;
	  			}
	  		};
	  		
	  		function checkDirector(){
	  			var flag=$("#directorid").val();
	  			if(flag!=""){
	  				return true;
	  			}else{
	  				return false;
	  			}
	  		};
	  		
	  		function checkShowtime(){
	  			var flag=$("#showTime").val();
	  			if(flag!=""){
	  				return true;
	  			}else{
	  				return false;
	  			}
	  		};
	 
	  		function check(){
	  			var f1 =checkIntroduce();
	  			var f2 =checkName();
	  			var f3 =checkTime();
	  			var f4 =checkImage();
	  			var f5 =checkPoster();
	  			var f6 =checkActor();
	  			var f7 =checkDirector();
	  			var f8 =checkShowtime();
	  			
	  			return f1&&f2&&f3&&f4&&f5&&f6&&f7&&f8;
	  		}
	  		$(function(){
	  			$("#form").submit(check);
	  		});
	  		</script>
	</div>
    </form>
</body>
</html>